import {
  getServerSideCategories,
  getServerSideProducts,
} from '@/services/back';
import { getCategoryByPaths, parseSearchParams } from '@/utils/common';
import CategoriesPage from '@/views/Categories';
import { notFound } from 'next/navigation';

export default async function Page(props: any) {
  console.log('=========== start app/catalogsearch/result/page ===========');
  const categories = await getServerSideCategories();

  // const params = parseSearchParams(props?.searchParams);
  const searchParams = props?.searchParams || {};
  const keyword = searchParams.q || '';
  const catId = Number(searchParams.cat) || 0;
  const currCategory =
    categories?.find((c: any) => c.category_id == catId) || null;
  const pageTitle = `Search results for “${keyword}”`;
  const skusInfo = null;
  return (
    <CategoriesPage
      {...props}
      paths={[pageTitle]}
      // filters={queryParams}
      pageTitle={pageTitle}
      category={currCategory}
      categories={categories || []}
      products={skusInfo || {}}
    />
  );
}
